package com.qing.apple.filter;

import com.qing.apple.filter.bean.Apple;
import com.qing.apple.filter.bean.Fruit;
import com.qing.apple.filter.bean.Orange;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;


public class Demo {

	public static void main(String[] args) {
		Function<Integer,Integer> f=x->x+1;
		Function<Integer,Integer> g=x->x+2;
		Function<Integer,Integer> h=f.andThen(g);


		System.out.println(h.apply(1)); //4


		Function<Integer,Integer> z=y->y+1;
		Function<Integer,Integer> k=y->y+2;
		Function<Integer,Integer> y=z.compose(k);
		System.out.println(y.apply(1));
	}

	/**
	 * 获取不同重量的苹果
	 * @param list
	 * @param f
	 * @return
	 */
	 public static List<Apple> map(List<Integer> list,Function<Integer,Apple> f){
		List<Apple> result=new ArrayList<>();
		for (Integer integer : list) {
			result.add(f.apply(integer));
		}
		return  result;
	}


	public static Map<String,Function<Integer, Fruit>> map=new HashMap<>();

	 static {
	 	map.put("apple",Apple::new);
		map.put("orange", Orange::new);

	 }
}
